package com.itheima.demo;

public class Demo_Er {
    public static void main(String[] args) {
        int[] arr = {11, 24, 46, 55, 66, 77};
        int number = 6;
        int index = findIndex(arr, number);
        System.out.println(index);
    }

    private static int findIndex(int[] arr, int number) {
        int left = 0;
        int reght = arr.length - 1;
        while (left <= reght) {
            int mid = left + (reght - left) / 2;
            if (arr[mid] > number && reght > left) {
                reght = mid - 1;
            } else if (arr[mid] < number && reght > left) {
                left = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
}
